package com.pointwest.pls.domainMapper;

import java.util.ArrayList;
import java.util.Map;

import com.pointwest.pls.constant.DBConstant;
import com.pointwest.pls.domain.Employee;
import com.pointwest.pls.domain.Project;
import com.pointwest.pls.domain.QuadrantSeat;
import com.pointwest.pls.domain.Seat;
import com.pointwest.pls.domain.SeatType;

public class MapperHelper {

	public static Employee mapEmployeeDaoToDomain(
			Map<String, String> employeeMap) {
		Employee employee = new Employee();

		employee.setId(Integer.parseInt(employeeMap.get(DBConstant.COL_EMPLOYEE_ID)));
		employee.setFirstName(employeeMap.get(DBConstant.COL_FIRST_NAME));
		employee.setLastName(employeeMap.get(DBConstant.COL_LAST_NAME));
		employee.setEmailAddress(employeeMap.get(DBConstant.COL_EMAIL_ADD));
		employee.setPositionCode(employeeMap.get(DBConstant.COL_POSITION_CODE));

		return employee;

	}

	public static Seat mapSeatDaoToDomain(Map<String, String> seatMap) {
		Seat seat = new Seat();
		Employee employee = new Employee();
		SeatType seatType = new SeatType();

		employee.setFirstName(seatMap.get(DBConstant.COL_FIRST_NAME));
		employee.setLastName(seatMap.get(DBConstant.COL_LAST_NAME));
		seat.setEmployee(employee);
		
		seatType.setDescription(seatMap.get(DBConstant.COL_SEAT_TYPE_DESC));
		seat.setSeatType(seatType);
		
		seat.setSeatCode(seatMap.get(DBConstant.COL_SEAT_CODE));
		seat.setQuadrant(seatMap.get(DBConstant.COL_QUADRANT));
		if (seatMap.get(DBConstant.COL_LOCAL_NO) != null) {
			seat.setLocalNumber(Integer.parseInt(seatMap.get(DBConstant.COL_LOCAL_NO)));
		}
		
		return seat;

	}
	
	public static ArrayList<QuadrantSeat> mapQuadrantSeatDaoToDomainList(ArrayList<Map<String, String>> quadrantSeatsMap) {
		ArrayList<QuadrantSeat> quadrantSeats = new ArrayList<QuadrantSeat>();
		
		for (Map<String,String> quadrantSeatMap : quadrantSeatsMap) {
			QuadrantSeat quadrantSeat = new QuadrantSeat();
			if (quadrantSeatMap.get(DBConstant.COL_EMPLOYEE_ID) != null) {
				quadrantSeat.setEmployeeId(quadrantSeatMap.get(DBConstant.COL_EMPLOYEE_ID));
			}
			quadrantSeat.setSeatCode(quadrantSeatMap.get(DBConstant.COL_SEAT_CODE));
			quadrantSeat.setSeatType(quadrantSeatMap.get(DBConstant.COL_SEAT_TYPE_DESC));
			quadrantSeat.setRow(Integer.parseInt(quadrantSeatMap.get(DBConstant.COL_ROW)));
			quadrantSeat.setColumn(Integer.parseInt(quadrantSeatMap.get(DBConstant.COL_COLUMN)));
			if (quadrantSeatMap.get(DBConstant.COL_LOCAL_NO) != null) {
				quadrantSeat.setLocalNumber(Integer.parseInt(quadrantSeatMap.get(DBConstant.COL_LOCAL_NO)));
			}
			quadrantSeats.add(quadrantSeat);
		}
		
		
		return quadrantSeats;
	}
	
	public static ArrayList<Project> mapProjectDaoToDomainList(ArrayList<Map<String, String>> projectListMap) {
		ArrayList<Project> projectList = new ArrayList<Project>();
		
		for (Map<String,String> projectMap : projectListMap) {
			Project project = new Project();
			project.setDescription(projectMap.get(DBConstant.COL_PROJECT_DESC));
			projectList.add(project);
		}
		
		return projectList;
	}

}
